'''

Case Type： 数据库系统
Case Name： 修改数据库参数的值work_mem大于最大值
Create At:  2020/06/24
Owner    :  @li-xin12345
Descption:  1.设置work_mem为2500000000KB，大于最大值(最大值为2147483647kB);2.设置参数时报错，设置不成功

history：
created： 2020/06/24  created by @li-xin12345
'''

import os
import unittest
import time
from yat.test import Node
from testcase.utils.CommonSH import *
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import *

from testcase.utils.Constant import Constant


class PortOccupied(unittest.TestCase):
    sh_primy = CommonSH('PrimaryDbUser')
    nodes_tuple = ('PrimaryDbUser', 'Standby1DbUser', 'Standby2DbUser')

    @RestartDbCluster(*nodes_tuple)
    def setUp(self):
        self.log = Logger()
        self.log.info('------------Opengauss_Reliability_Dbsys_Case112.py start------------')
        self.rootNode = Node('PrimaryRoot')
        self.primaryNode = Node(node='PrimaryDbUser')
        self.SOURCE_PATH = macro.DB_ENV_PATH
        self.Constant = Constant()
        self.work_mem = 2500000000

    def test_work_mem_set_max_values(self):
        self.log.info('------------------更改参数work_mem=2500000000------------------------------')
        set_cmd = f'''
                   source {self.SOURCE_PATH};
                   gs_guc set -N all -I all -c work_mem={self.work_mem};
                 '''
        set_msg = self.primaryNode.sh(set_cmd).result()
        self.log.info(set_msg)
        res = set_msg.find(self.Constant.OUTSIDE_MSG) > -1
        self.assertTrue(res)
        self.log.info(set_msg)

    def tearDown(self):
        self.log.info('----------------------------后置处理-----------------------------')
        try:
            db_status = self.sh_primy.getDbClusterStatus('status')
            self.log.info(db_status)
            if db_status:
                pass
            else:
                is_started = self.sh_primy.startDbCluster()

                self.assertTrue(is_started)
                self.log.info(f'{is_started}')
                self.log.info(f'db_status: {is_started}')
        finally:
            db_status = self.sh_primy.getDbClusterStatus('status')
            self.log.info(db_status)
        self.log.info('------------------reliability_dbsys112 执行完成------------------------------')
